package com.zhangzhan.gulimallproduct.app;

import com.zhangzhan.gulimallcommcon.exception.valid.AddGroup;
import com.zhangzhan.gulimallcommcon.exception.valid.UpdateGroup;
import com.zhangzhan.gulimallcommcon.exception.valid.UpdateStatus;
import com.zhangzhan.gulimallcommcon.util.PageUtils;
import com.zhangzhan.gulimallcommcon.util.R;
import com.zhangzhan.gulimallproduct.entity.BrandEntity;
import com.zhangzhan.gulimallproduct.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 品牌
 *
 * @author zhangzhan
 * @email sunlightcs@gmail.com
 * @date 2024-06-12 16:45:44
 */
@RestController
@RequestMapping("gulimallproduct/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("gulimallproduct:brand:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{brandId}",method = RequestMethod.GET)
    //@RequiresPermissions("gulimallproduct:brand:info")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("gulimallproduct:brand:save")
    public R save(@RequestBody @Validated(AddGroup.class) BrandEntity brand){
		brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gulimallproduct:brand:update")
    public R update(@Validated(value = UpdateGroup.class) @RequestBody BrandEntity brand){
		brandService.updateByIdAndintermediateTable(brand);

        return R.ok();
    }


    /**
     * 修改显示状态
     */
    @RequestMapping("/update/showStatus")
    //@RequiresPermissions("gulimallproduct:brand:update")
    public R updateShowStatus(@Validated(value = UpdateStatus.class) @RequestBody BrandEntity brand){
        brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gulimallproduct:brand:delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
